package com.mc.web;

import org.apache.log4j.Logger;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.SessionAttributes;


import com.mc.model.Path;
import com.mc.model.SubMenu;
import com.mc.model.Tmenu;
import com.mc.service.MenuService;
import com.mc.service.SubMenuService;
import com.mc.service.TmenuService;
import com.mc.service.UserService;
import com.mc.utils.TraderCenterUtil;

@Controller
//@RequestMapping("/backend")
@SessionAttributes("user")
public class BackendAction {
	/**
	 * Logger for this class
	 */
	private static final Logger logger = Logger.getLogger(BackendAction.class);

	@Autowired
	private UserService userService;
	
	@Autowired private MenuService menuService;
	@Autowired private SubMenuService subMenuService;
	@Autowired private TmenuService tmenuService;
	private Path path = null;
	
	@RequestMapping("/getsubmenus")
	@ResponseBody
	public String getSubMenus(@RequestParam(value="pmid",required=true)int pmid,ModelMap map)
	{
		
		List<SubMenu> smenus = subMenuService.selectSubMenuByMid(pmid);
		String smenujson = TraderCenterUtil.getInstance().ParseListToJSON(smenus);
		//logger.info(smenujson + "----");
		return smenujson;
	}
	@RequestMapping("/gettmenus")
	@ResponseBody
	public String getTmenus(@RequestParam("sid")int sid)
	{
		//logger.info(sid + "----sid");
		List<Tmenu> tmenus = tmenuService.selectTmenuBysid(sid);
		String tmenujson = TraderCenterUtil.getInstance().ParseListToJSON(tmenus);
		return tmenujson;
	}
	@RequestMapping("/AcaIntro")
	public String setAcaIntro(@RequestParam(value="content",required = true) String content)
	{
		
		return "";
	}
	@RequestMapping("/adddata")
	public String addData(@RequestParam(value="pmenu",required=true)int pmid,
			@RequestParam(value="smenu",required=true) int sid,
			@RequestParam(value="tmenu",required=true) int tid,
			@RequestParam(value="context",required=true) String context)
	{
		//logger.info(pmid +" "+ sid + " " + tid + " \n" + context);
		
		return "";
	}
	
}
